package com.tistory.aporie.sticker;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.View;

public class StikerPaneView extends View {

	private static final int DEFAULT_WIDTH = 100;
	
	private static final int DEFAULT_HEIGHT = 100;
	
	
	public StikerPaneView(Context context) {
		this(context, null);
	}

	public StikerPaneView(Context context, AttributeSet attrs) {
		super(context, attrs, 0);
	}
	
	public StikerPaneView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		
		//TODO
		//TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.StkerPaneView);
		//int mode = typedArray.getInt(R.styleable.StkerPaneView, 0);
	}
	
	@Override
	protected void onFinishInflate() {
		// TODO Auto-generated method stub
		super.onFinishInflate();
	}

	// default size 100 x 100
	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

		int heightMode = MeasureSpec.getMode(heightMeasureSpec);
        int heightSize = 0;
        switch(heightMode) {
        case MeasureSpec.UNSPECIFIED:	// unspecified
            heightSize = heightMeasureSpec;
            break;
        case MeasureSpec.AT_MOST:        // wrap_content
            heightSize = DEFAULT_HEIGHT + getPaddingLeft() + getPaddingRight();
            break;
        case MeasureSpec.EXACTLY:        // fill_parent, match_parent
            heightSize = MeasureSpec.getSize(heightMeasureSpec);
            break;
        }
        
        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
        int widthSize = 0;
        switch(widthMode) {
        case MeasureSpec.UNSPECIFIED:	// unspecified
            widthSize = widthMeasureSpec;
            break;
        case MeasureSpec.AT_MOST:        // wrap_content
            widthSize = DEFAULT_WIDTH + getPaddingTop() + getPaddingBottom();
            break;
        case MeasureSpec.EXACTLY:        // fill_parent, match_parent
            widthSize = MeasureSpec.getSize(widthMeasureSpec);
            break;
        }

        setMeasuredDimension(widthSize, heightSize);
	}
	
	@Override
	protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
		// TODO - gravity 값에 의해 변동되는 위치를 적용 
	}
	
	@Override
	protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
		// TODO Auto-generated method stub
		super.onSizeChanged(width, height, oldWidth, oldHeight);
	}
	
	@Override
	protected void onDraw(Canvas canvas) {
		
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		
		
		return super.onTouchEvent(event);
	}
	
	private float getPixelSize(float dip){
		
		return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, getResources().getDisplayMetrics());
	}
}
